package com.hui.wanxin.web.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 灰灰
 * @date: 2023年10月11日 21:47
 * @ClassName: R
 * @Description: TODO
 */
@Data
public class R {

    private Integer code;
    private String msg;
    private Object data;

    public static R toAjax(Integer row){
        return row == 1 ? success(): error();
    }
    public static R toAjax(Boolean row){
        return row ? success(): error();
    }

    public static R success() {
        R r = new R();
        r.code = 0;
        r.msg = "success";
        return r;
    }

    public static R success(String msg, Object data) {
        R r = new R();
        r.code = ResultCode.SUCCESS;
        r.data = data;
        r.msg = msg;
        return r;
    }

    public static R success(Object data) {
        R r = new R();
        r.code = ResultCode.SUCCESS;
        r.data = data;
        return r;
    }

    public static R error() {
        R r = new R();
        r.code = ResultCode.ERROR;
        r.msg = "error";
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.code = ResultCode.ERROR;
        r.msg = msg;
        return r;
    }

    public static R sendMessage(Integer code, String msg) {
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static R sendMessage(Integer code, String msg, Object data) {
        R r = new R();
        r.code = code;
        r.data = data;
        r.msg = msg;
        return r;
    }

}
